package com.xx.ems.model;

import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

/**
 * @author xxx
 * @date 2014-3-3
 * @version 1.0
 * 描述: 领用单号表
 */
@Entity
public class ReceiveNum {
	/**
	 * 描述：主键
	 */
	private int rid;
	/**
	 * 描述：领用单号
	 */
	private String rnum;
	/**
	 * 描述：用户表关联对象 (领用人)
	 */
	private Users users;
	/**
	 * 描述：用户表关联对象 (领用操作人)
	 */
	private Users busers;
	/**
	 * 描述：领用时间
	 */
	private Date borrow_time;
	/**
	 * 描述：领用表关联对象
	 */
	private Set<Receive> receive = new HashSet<Receive>();
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="rid",unique=true,nullable=false)
	public int getRid() {
		return rid;
	}
	public void setRid(int rid) {
		this.rid = rid;
	}
	@Column(name="rnum",length=20,nullable=false)
	public String getRnum() {
		return rnum;
	}
	public void setRnum(String rnum) {
		this.rnum = rnum;
	}
	@ManyToOne(targetEntity=Users.class)
	@JoinColumn(name="fk_uid")
	public Users getUsers() {
		return users;
	}
	public void setUsers(Users users) {
		this.users = users;
	}
	@ManyToOne(targetEntity=Users.class)
	@JoinColumn(name="fk_buid")
	public Users getBusers() {
		return busers;
	}
	public void setBusers(Users busers) {
		this.busers = busers;
	}
	@Column(name="borrow_time",nullable=false)
	public Date getBorrow_time() {
		return borrow_time;
	}
	public void setBorrow_time(Date borrow_time) {
		this.borrow_time = borrow_time;
	}
	@OneToMany(targetEntity=Receive.class,mappedBy="receiveNum")
	public Set<Receive> getReceive() {
		return receive;
	}
	public void setReceive(Set<Receive> receive) {
		this.receive = receive;
	}
	/**
	 * 描述: 将实体的属性及相应的值转换成Map类型(为了方便转换成json格式后前台调用) 
	 * @return
	 * @date 2014-3-4
	 */
	public Map<String, Object> toHashMap(){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("rid", getRid());
		map.put("rnum", getRnum());
		map.put("user", getUsers().getUsername());
		map.put("buser", getBusers());
		map.put("borrow_time", getBorrow_time());
		return map;
	}
}